package com.rk.client;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class HDFSClient {

    private FileSystem fs;

    public HDFSClient() throws URISyntaxException, IOException, InterruptedException {
        Configuration configuration = new Configuration();
        this.fs = FileSystem.get(new URI("hdfs://192.168.45.101:9000"), configuration, "root");
    }

    public void mkdirs(String path) throws IOException {
        fs.mkdirs(new Path(path));
        fs.close();
    }

    public void uploadFile(String filePath, String remotePath) throws IOException {
        fs.copyFromLocalFile(new Path(filePath), new Path(remotePath));
        fs.close();
    }
}
